#include <iostream>
#include <unordered_map>
#include <string>
#include <gtest/gtest.h>

class myEnvironment : public testing::Environment
{
public:
    virtual void SetUp() override
    {
        std::cout << "测试前准备测试环境\n";
    }
    virtual void TearDown() override
    {
        std::cout << "测试完毕后清理测试环境\n";
    }
};

TEST(myEnvironment, test1)
{
    std::cout << "单元测试1\n";
}
TEST(myEnvironment, test2)
{
    std::cout << "单元测试2\n";
}

static std::unordered_map<std::string, std::string> aMap;
class myMap : public testing::Environment
{
public:
    virtual void SetUp() override
    {
        std::cout << "测试前准备测试环境\n";
        aMap.insert(std::make_pair("wangshu", "大帅b"));
        aMap.insert(std::make_pair("hello", "你好"));
    }
    virtual void TearDown() override
    {
        std::cout << "测试完毕后清理测试环境\n";
        aMap.clear();
    }
};

TEST(myMap, test1)
{
    ASSERT_EQ(aMap.size(), 2);
    aMap.erase("hello");
}
TEST(myMap, test2)
{
    ASSERT_EQ(aMap.size(), 2);
}

int main(int argc, char* argv[])
{
    testing::AddGlobalTestEnvironment(new myEnvironment);
    testing::AddGlobalTestEnvironment(new myMap);
    testing::InitGoogleTest(&argc, argv);
    RUN_ALL_TESTS();
    return 0;
}